package com.fmjava.service_video.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.util.StringUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fmjava.service_video.entity.Author;
import com.fmjava.service_video.entity.vo.AuthorQuery;
import com.fmjava.service_video.mapper.AuthorMapper;
import com.fmjava.service_video.service.AuthorService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 创作者 服务实现类
 * </p>
 *
 * @author fmjava
 * @since 2021-07-01
 */
@Service
public class AuthorServiceImpl extends ServiceImpl<AuthorMapper, Author> implements AuthorService {

    @Override
    public void pageQuery(Page<Author> pageInfo, AuthorQuery authorQuery) {
        QueryWrapper<Author> wrapper = new QueryWrapper<>();
        if(authorQuery==null)
        {
            baseMapper.selectPage(pageInfo, wrapper);
            return;
        }
        if(authorQuery!=null)
        {
            if(!StringUtils.isEmpty(authorQuery.getName())){
                wrapper.like("name",authorQuery.getName());
            }
            if (!StringUtils.isEmpty(authorQuery.getLevel())){
                wrapper.eq("level",authorQuery.getLevel());
            }
            //查询创建按时间大于 begin这个时间
            if(!StringUtils.isEmpty(authorQuery.getBegin())){
                wrapper.ge("gmt_create",authorQuery.getBegin());
            }
            //查询创建时间小于 end 这个时间
            if (!StringUtils.isEmpty(authorQuery.getEnd())){
                wrapper.le("gmt_create",authorQuery.getEnd());
            }
        }
        baseMapper.selectPage(pageInfo, wrapper);
    }
}
